﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dack_Web2.BUS;
using System.Data.OleDb;

namespace Dack_Web2
{
    public partial class QuanLyDeal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (CurrentContext.IsLogged)
            {
                if (CongTyBUS.GetCongTy(CurrentContext.UserName) == null)
                {
                    Response.Redirect("~/Default.aspx");
                }
                else
                {
                    string str = "select * from SanPham, Deal, GioHang where Deal.MaDeal = GioHang.MaDeal and Deal.MaSanPham = SanPham.MaSanPham and MaUser=" + Dack_Web2.User.FromId(CurrentContext.UserName).MaUser;
                    GridView1.DataSource = Sql_DataProvider.SQL_ExecuteTable(str);
                    GridView1.DataBind();
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string str = "update [GioHang] set TinhTrang=@TinhTrang where MaGioHang=@MaGioHang";
            OleDbParameter[] pr = {new OleDbParameter("@TinhTrang", "Đã giao"),
                                   new OleDbParameter("@MaGioHang",int.Parse( GridView1.SelectedRow.Cells[0].Text.ToString()))};

            Sql_DataProvider.SQL_ExecuteNonQuery(str, pr);

            Response.Redirect("QuanLyDeal.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string str = "delete from [GioHang] where MaGioHang=@MaGioHang";
            OleDbParameter[] pr = { new OleDbParameter("@MaGioHang", int.Parse( GridView1.SelectedRow.Cells[0].Text)) };

            Sql_DataProvider.SQL_ExecuteNonQuery(str, pr);

            Response.Redirect("QuanLyDeal.aspx");
        }
    }
}